<?php
//引擎抽象产品
abstract class EngineProduct{
	abstract function engine();
}
class CarEngine extends EngineProduct{
	public function engine(){
		echo '汽车引擎<br/>';
	}
}
class BusEngine extends EngineProduct{
	public function engine(){
		echo '巴士引擎<br/>';
	}
}
//外壳抽象产品
abstract class ShellProduct{
	abstract function shell();
}
class CarShell extends ShellProduct{
	public function shell(){
		echo '汽车外壳<br/>';
	}
}
class BusShell extends ShellProduct{
	public function shell(){
		echo '巴士外壳<br/>';
	}
}
//抽象工厂
abstract class Factory{
	abstract function createEngine();
	abstract function createShell();
}
//汽车具体工厂
class CarFactory extends Factory{
	public function createEngine(){
		return new CarEngine();
	}
	public function createShell(){
		return new CarShell();
	}
}
//巴士具体工厂
class BusFactory extends Factory{
	public function createEngine(){
		return new BusEngine();
	}
	public function createShell(){
		return new BusShell();
	}
}

$carFactory = new CarFactory();
$engine = $carFactory->createEngine();
$engine->engine();
$shell = $carFactory->createShell();
$shell->shell();

$busFactory = new BusFactory();
$engine = $busFactory->createEngine();
$engine->engine();
$shell = $busFactory->createShell();
$shell->shell();
?>